CodeForces 您所在的位置:网站首页 cow horse friend CodeForces

CodeForces

2023-04-02 06:54| 来源: 网络整理| 查看: 265

题目链接:点击查看

题目大意:在二维平面上,要求从点 ( 0 , 0 ) 到点 ( x , 0 ) 处,每次只能行走给出的路径长度,问最少需要走几次才能到

题目分析:读完题后首先想到的是三角形,如果想组成三角形,那么必须满足两边之和大于第三边,当然在这个题目中稍微特殊一点,两边之和也可以等于第三边,这也就说,如果给出的长度的最大值大于 x 时,答案一定是 2 ,因为利用两条最大值的长度和 x 的长度,一定能组成一个锐角的等腰三角形,当给出长度的最大值小于 x 时,最优的答案肯定是先用这个最大值沿着 x 轴一直铺过去,尽可能的将其变为上面的第一种情况就好了,那么此时的答案就是 (x / mmax) 向上取整

到这就完了嘛?如果只是实现上述的操作,看似天衣无缝,但这个题目中还隐藏着一个小坑点,就是如果给出的数据中,存在一条边与 x 相等时,那么答案是 1 。因为这个特判整整卡了我一个小时。。太自闭了

代码:  

#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int N=1e5+100; int a[N]; int main() { //#ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); //#endif // ios::sync_with_stdio(false); int w; cin>>w; while(w--) { int n,m; bool flag=false; scanf("%d%d",&n,&m); for(int i=1;i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有